
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>数组运算 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="operation.html" />
    
    
    <link rel="prev" href="numpy.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../redis.html">
            
                <a href="../redis.html">
            
                    
                    redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../ubuntu.html">
            
                <a href="../ubuntu.html">
            
                    
                    ubuntu
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../wsgi.html">
            
                <a href="../wsgi.html">
            
                    
                    wsgi
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../vue整合.html">
            
                <a href="../vue整合.html">
            
                    
                    vue整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../app打包.html">
            
                <a href="../app打包.html">
            
                    
                    app打包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="preview.html">
            
                <a href="preview.html">
            
                    
                    numpy概览
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="numpy.html">
            
                <a href="numpy.html">
            
                    
                    创建数组
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.2" data-path="math.html">
            
                <a href="math.html">
            
                    
                    数组运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="operation.html">
            
                <a href="operation.html">
            
                    
                    数组操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="usea.html">
            
                <a href="usea.html">
            
                    
                    算法应用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >数组运算</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x6570;&#x7EC4;&#x8FD0;&#x7B97;">&#x6570;&#x7EC4;&#x8FD0;&#x7B97;</h3>
<ol>
<li><p>&#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x503C;&#x7684;&#x8FD0;&#x7B97;</p>
<pre><code> &#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x503C;&#x7684;&#x8FD0;&#x7B97;
  x = np.array((1, 2, 3, 4, 5))    # &#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;
  x * 2                            # &#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x503C;&#x76F8;&#x4E58;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;
 &gt;&gt;&gt;array([ 2, 4, 6, 8, 10])

  x / 2                            # &#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x503C;&#x76F8;&#x9664;
 &gt;&gt;&gt;array([ 0.5, 1. , 1.5, 2. , 2.5])

  x // 2                           # &#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x503C;&#x6574;&#x9664;
 &gt;&gt;&gt;array([0, 1, 1, 2, 2], dtype=int32)

  x ** 3                           # &#x5E42;&#x8FD0;&#x7B97;
 &gt;&gt;&gt;array([1, 8, 27, 64, 125], dtype=int32)

  x + 2                            # &#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x503C;&#x76F8;&#x52A0;
 &gt;&gt;&gt;array([3, 4, 5, 6, 7])

  x % 3                            # &#x4F59;&#x6570;
 &gt;&gt;&gt;array([1, 2, 0, 1, 2], dtype=int32)
</code></pre></li>
<li><p>&#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x7EC4;&#x7684;&#x8FD0;&#x7B97;</p>
<pre><code> a = np.array((1, 2, 3))
 b = np.array(([1, 2, 3], [4, 5, 6], [7, 8, 9]))
 c = a * b                   # &#x6570;&#x7EC4;&#x4E0E;&#x6570;&#x7EC4;&#x76F8;&#x4E58;
 c                           # a&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x4E58;&#x4EE5;b&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x5217;&#x5143;&#x7D20;
 &gt;&gt;&gt;array([[ 1, 4, 9],
    [ 4, 10, 18],
    [ 7, 16, 27]])
 c / b                       # &#x6570;&#x7EC4;&#x4E4B;&#x95F4;&#x7684;&#x9664;&#x6CD5;&#x8FD0;&#x7B97;
 &gt;&gt;&gt;array([[ 1.,  2.,  3.],
    [ 1.,  2.,  3.],
    [ 1.,  2.,  3.]])
 c / a
 &gt;&gt;&gt;array([[ 1.,  2.,  3.],
    [ 4.,  5.,  6.],
    [ 7.,  8.,  9.]])

 a + a                         # &#x6570;&#x7EC4;&#x4E4B;&#x95F4;&#x7684;&#x52A0;&#x6CD5;&#x8FD0;&#x7B97;
 &gt;&gt;&gt;array([2, 4, 6])

 a - a                         # &#x6570;&#x7EC4;&#x4E4B;&#x95F4;&#x7684;&#x51CF;&#x6CD5;&#x8FD0;&#x7B97;
 &gt;&gt;&gt;array([0, 0, 0])
</code></pre></li>
<li><p>&#x6570;&#x7EC4;&#x8F6C;&#x7F6E;</p>
<pre><code> b = np.array(([1, 2, 3], [4, 5, 6], [7, 8, 9]))
 b
 &gt;&gt;&gt;array([[1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]])
 b.T                           # &#x8F6C;&#x7F6E;
 &gt;&gt;&gt;array([[1, 4, 7],
    [2, 5, 8],
    [3, 6, 9]])
 a = np.array((1, 2, 3, 4))
 a
 &gt;&gt;&gt;array([1, 2, 3, 4])
 a.T                           # &#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#x8F6C;&#x7F6E;&#x4EE5;&#x540E;&#x548C;&#x539F;&#x6765;&#x662F;&#x4E00;&#x6837;&#x7684;
 &gt;&gt;&gt;array([1, 2, 3, 4])
</code></pre></li>
<li><p>&#x8BA1;&#x7B97;&#x5185;&#x79EF;</p>
<pre><code> a = np.array((5, 6, 7))
 b = np.array((6, 6, 6))
 a.dot(b)                                    # &#x5411;&#x91CF;&#x5185;&#x79EF;
 &gt;&gt;&gt;108
 np.dot(a,b)
 &gt;&gt;&gt;108
</code></pre></li>
</ol>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="numpy.html" class="navigation navigation-prev " aria-label="Previous page: 创建数组">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="operation.html" class="navigation navigation-next " aria-label="Next page: 数组操作">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"数组运算","level":"1.7.2","depth":2,"next":{"title":"数组操作","level":"1.7.3","depth":2,"path":"numpy/operation.md","ref":"numpy/operation.md","articles":[]},"previous":{"title":"创建数组","level":"1.7.1","depth":2,"path":"numpy/numpy.md","ref":"numpy/numpy.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"numpy/math.md","mtime":"2018-09-01T17:00:59.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-02T04:20:29.430Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

